package tmproject.hlhj.fhp.cartrans.modules

import android.content.Context
import com.example.mymvp.BaseModule
import com.lzy.okgo.model.Response
import io.reactivex.disposables.Disposable
import tmproject.hlhj.fhp.cartrans.http.Apis
import tmproject.hlhj.fhp.cartrans.http.BaseAciton
import tmproject.hlhj.fhp.cartrans.http.LoadingAction
import tmproject.hlhj.fhp.cartrans.javaBean.BaseBean
import tmproject.hlhj.fhp.cartrans.javaBean.CarNumBean
import tmproject.hlhj.fhp.cartrans.javaBean.RegisBean
import java.io.File

/**
 * Created by Administrator on 2018/8/11/011.
 */
class RegisModule :BaseModule {
    var listener:RegisResp?=null
    //注册
    fun tryRegis(c:Context,name:String, mobile:String, sex:String, age:Int, id_no:String
                 , jsz_expire_date:String, zgz_expire_date:String, tractor_id:String, id_pic: File, id_pic_back: File
                 , jsz_pic: File, zgz_pic: File){
        Apis.regis(name, mobile, sex, age, id_no, jsz_expire_date, zgz_expire_date, tractor_id, id_pic, id_pic_back, jsz_pic, zgz_pic)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :BaseAciton<Response<RegisBean>>{
                                override fun onSubscribe(d: Disposable) {

                                }

                                override fun httpSuccess(t: Response<RegisBean>) {
                                    listener?.onRegisResult(t.body())
                                }

                                override fun httpErroCode(baseBean: BaseBean) {
                                }

                                override fun httpFailed(e: Throwable?) {
                                }
                            })
                }
    }

    fun getCarNum(c:Context){
        Apis.getCarNum()
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :BaseAciton<Response<CarNumBean>>{
                                override fun onSubscribe(d: Disposable) {

                                }

                                override fun httpSuccess(t: Response<CarNumBean>) {
                                    listener?.onCarNumResult(t.body())
                                }

                                override fun httpErroCode(baseBean: BaseBean) {
                                }

                                override fun httpFailed(e: Throwable?) {
                                }
                            })
                }
    }
    interface RegisResp{
        fun onRegisResult(regisBean: RegisBean)
        fun onCarNumResult(carNumBean: CarNumBean)
    }
}